package com.example.tests;

import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.*;

import org.testng.annotations.Test;
import com.example.utils.SortedListOf;

public class GroupRemovalTests extends TestBase {
	
  @Test
  public void deleteSomeGroup() {
    
    //save old state
//  	SortedListOf<GroupData> oldList = new SortedListOf<GroupData>(app.getHibernateHelper().listGroups());
  	SortedListOf<GroupData> oldList = app.getModelGroups().getGroups();
    
    int index = app.getGroupHelper().getRandomGroupIndex(oldList);    	

    if (index > 0) {
	    // actions
	    app.getGroupHelper().deleteGroup(index);
	    
	    // save new state
//	    SortedListOf<GroupData> newList = app.getGroupHelper().getUiGroups();
	    SortedListOf<GroupData> newList = app.getModelGroups().getGroups();
	    
	    // compare state states before and after
	    // remember to handle empty list situation
	    assertThat(newList, equalTo(oldList));
	    
	    // compare model to implementation
      if ("yes".equals(app.getProperty("check.db"))) {
        assertThat(app.getModelGroups().getGroups(), equalTo(app.getHibernateHelper().listGroups()));
        System.out.println("DB check done. On group: " + index);
      }
      
      if ("yes".equals(app.getProperty("check.ui"))) {
        assertThat(app.getModelGroups().getGroups(), equalTo(app.getGroupHelper().getUiGroups()));
        System.out.println("UI check done. On group: " + index);
      }
      
    }
   }

}
